﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <script>
        
        // 封装一个数学对象，里面有 PI, 求数组的最大值和最小值
        let myMath = {
            PI: 3.14,
            getMax: function (arr) {
                let max = arr[0];
                for (var i in arr) {
                    if (arr[i] > max) {
                        max = arr[i];
                    }
                } return max;
            },
            getMin: function (arr) {
                let min = arr[0];
                for (let i in arr) {
                    if (arr[i] < min) {
                        min = arr[i];
                    }
                } return min;
            },
        }
        console.log(myMath.PI);
        let arr = [2, 15, 5, 6]
        console.log(myMath.getMax(arr));
        console.log(myMath.getMin(arr));
    </script>
</body>
</html>